USE NutritionTracker
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'AppUser_MeasurementUnit') AND type in (N'U'))
	DROP TABLE AppUser_MeasurementUnit
GO
CREATE TABLE	AppUser_MeasurementUnit
(
	AppUserID	INT	NOT NULL,
	MeasurementTypeID	TINYINT NOT NULL,
	MeasurementUnitID	TINYINT NOT NULL,
	CONSTRAINT pk_AppUser_MeasurementUnit PRIMARY KEY(AppUserID ASC,MeasurementTypeID ASC)
)
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'fk_AppUser_MeasurementUnit_MeasurementUnit') AND parent_object_id = OBJECT_ID(N'AppUser_MeasurementUnit'))
	ALTER TABLE AppUser_MeasurementUnit  WITH CHECK ADD  CONSTRAINT fk_AppUser_MeasurementUnit_MeasurementUnit FOREIGN KEY(MeasurementUnitID) REFERENCES MeasurementUnit (MeasurementUnitID)
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'fk_AppUser_MeasurementUnit_AppUser') AND parent_object_id = OBJECT_ID(N'AppUser_MeasurementUnit'))
	ALTER TABLE AppUser_MeasurementUnit  WITH CHECK ADD  CONSTRAINT fk_AppUser_MeasurementUnit_AppUser FOREIGN KEY(AppUserID) REFERENCES AppUser (AppUserID)
GO